package com.yc.testparm;

import java.util.ArrayList;
import java.util.List;

public class TestRecursion {
	
	private String[] getOhter(String[] all, int i) {
		
		String[] other = new String[all.length-1];
		int x = 0;
		for (int j = 0; j < all.length; j++) {
			if (i != j) {
				other[x] = all[j];
				x++;
			}
		}
		
		return other;
	}
	
	
	
	public List<String> mt(List<String> haveParm, String[] parm) {
		List<String> result = new ArrayList<String>();
		if (parm.length == 1) {
			result.add(parm[0]);
			return result;
		}
		
		StringBuffer itemStr = new StringBuffer();
		
		String firstChar = null;
		String[] otherParm = null;
		List<String> otherRes = null;
		for (int i = 0; i < parm.length; i++) {
			firstChar = parm[i];
			haveParm.add(firstChar);
			otherParm = getOhter(parm, i);
			otherRes = mt(haveParm, otherParm);
			
			for (String otherStr : otherRes) {
				itemStr.setLength(0);
				itemStr.append(firstChar);
				itemStr.append(otherStr);
				result.add(itemStr.toString());
			}
			
			
		}
		
		return result;
	}

	public static void main(String[] args) {
		String[] param = new String[] {"a","b","c","d"};
		TestRecursion tr = new TestRecursion();
		List<String> list = tr.mt(new ArrayList<String>(),param);
		for (String str : list) {
			System.out.println(str);
		}
	}

}
